import React, { useState } from 'react';
import dynamic from 'next/dynamic'
// import LazyComponent from '../../components/LazyComponent'

// 懒加载组件 会单独打包成一个文件，需要的时候再加载
const LazyComponent = dynamic(import('../../components/lazyComponent'))

function LazyMoment() {
  const [nowTime, setNowTime] = useState(Date.now())
  // 将方法变成异步
  const changeTime = async () => {
    // 等待 moment 加载完成
    const monent = await import('moment')
    setNowTime(monent.default(Date.now()).format())
  }

  return (
    <>
      <h2>显示时间为：{nowTime}</h2>
      <LazyComponent />
      <button onClick={changeTime}>改变时间格式</button>
    </>
  )
}

export default LazyMoment
